﻿using UnityEditor;
using UnityEngine;

namespace EditorExtension
{
    public class EditorGUI_API
    {
        private Rect mLabelRect = new Rect(10, 50, 200, 20);
        private Rect mTextFiledRect = new Rect(10, 80, 200, 20);
        private Rect mTextAreaRect = new Rect(10, 110, 200, 40);
        private Rect mPasswordFieldRect = new Rect(10, 160, 200, 20);
        private Rect mDropdownButtonRect = new Rect(10, 190, 200, 20);
        private Rect mLinkButtonRect = new Rect(10, 220, 200, 20);
        private Rect mToggleRect = new Rect(10, 250, 200, 20);
        private Rect mToggleLeftRect = new Rect(10, 280, 200, 20);
        private Rect mHelpBoxRect = new Rect(10, 310, 200, 20);
        private Rect mColorFieldRect = new Rect(10, 340, 200, 20);
        private Rect mBoundsFieldRect = new Rect(10, 370, 200, 60);
        private Rect mBoundsIntFieldRect = new Rect(10, 440, 200, 60);
        private Rect mCurveFieldRect = new Rect(10, 510, 200, 20);
        private Rect mDelayedDoubleFieldRect = new Rect(10, 540, 200, 20);
        private Rect mDoubleFieldRect = new Rect(10, 570, 200, 20);
        private Rect mEnumFlagsFieldRect = new Rect(10, 600, 200, 20);
        private Rect mEnumPopupRect = new Rect(10, 630, 200, 20);
        private Rect mFoldoutRect = new Rect(250, 60, 300, 20);
        private Rect mGradientFieldRect = new Rect(250, 90, 300, 20);
        
        private bool mDisabledGroup = false;
        private string mTextFieldValue = "TextField: Hello EditorGUI API";
        private string mTextAreaValue = "TextArea:\n Hello EditorGUI API";
        private string mPasswordFieldValue = "PasswordField: Hello EditorGUI API";
        private bool mToggleValue = false;
        private Color mColorFieldValue = Color.red;
        private Bounds mBoundsFieldValue = new Bounds(Vector3.zero, Vector3.one);
        private BoundsInt mBoundsIntFieldValue = new BoundsInt(Vector3Int.zero, Vector3Int.one);
        private AnimationCurve mCurveFieldValue = AnimationCurve.Linear(0, 0, 1, 1);
        private double mDoubleValue = 0.0;

        private enum EnumFlagsFieldValue
        {
            A = 1,
            B = 2,
            C = 4,
            D = 8,
            E = 16,
            F = 32,
            G = 64,
            H = 128,
            I = 256,
            J = 512,
        }
        private EnumFlagsFieldValue mEnumFlagsFieldValue = EnumFlagsFieldValue.A;
        private EnumFlagsFieldValue mEnumPopupValue = EnumFlagsFieldValue.A;
        private bool mFoldoutValue = true;
        private Gradient mGradientFieldValue = new Gradient();
        
        public void Draw()
        {
            // 开关
            mDisabledGroup = EditorGUILayout.Toggle("是否可交互", mDisabledGroup);
            
            // 折叠
            mFoldoutValue = EditorGUI.Foldout(mFoldoutRect, mFoldoutValue, "Foldout");
            if (mFoldoutValue)
            {
                // 控制是否可交互
                EditorGUI.BeginDisabledGroup(mDisabledGroup);
                {
                    EditorGUI.LabelField(mLabelRect, "LabelField: Hello EditorGUI API"); // 文本
                    
                    mTextFieldValue = EditorGUI.TextField(mTextFiledRect, mTextFieldValue); // 文本输入框
                    
                    mTextAreaValue = EditorGUI.TextArea(mTextAreaRect, mTextAreaValue); // 文本输入区域

                    mPasswordFieldValue = EditorGUI.PasswordField(mPasswordFieldRect, mPasswordFieldValue); // 密码输入框
                    
                    // DropdownButton
                    if (EditorGUI.DropdownButton(mDropdownButtonRect, new GUIContent("123"), FocusType.Keyboard))
                    {
                        Debug.Log("DropdownButton Clicked");
                    }
                    
                    // LinkButton
                    if (EditorGUI.LinkButton(mLinkButtonRect, "Link Button"))
                    {
                        Debug.Log("LinkButton Clicked");
                    }
                    
                    // 开关
                    mToggleValue = EditorGUI.Toggle(mToggleRect, mToggleValue);
                    
                    // 文本在右的开关
                    mToggleValue = EditorGUI.ToggleLeft(mToggleLeftRect, "ToggleLeft", mToggleValue);
                    
                    // 提示框
                    EditorGUI.HelpBox(mHelpBoxRect, "HelpBox: Hello EditorGUI API", MessageType.Info);
                    
                    // 取色器
                    mColorFieldValue = EditorGUI.ColorField(mColorFieldRect, "ColorField", mColorFieldValue);
                    
                    // 边框
                    mBoundsFieldValue = EditorGUI.BoundsField(mBoundsFieldRect, "BoundsField", mBoundsFieldValue);
                    
                    // 边框Int
                    mBoundsIntFieldValue = EditorGUI.BoundsIntField(mBoundsIntFieldRect, "BoundsIntField", mBoundsIntFieldValue);
                    
                    // 曲线
                    mCurveFieldValue = EditorGUI.CurveField(mCurveFieldRect, "CurveField", mCurveFieldValue);
                    
                    // 数值输入框 -- 延迟变化
                    mDoubleValue = EditorGUI.DelayedDoubleField(mDelayedDoubleFieldRect, "DelayedDoubleField", mDoubleValue);
                    
                    // 数值输入框 -- 实时变化
                    mDoubleValue = EditorGUI.DoubleField(mDoubleFieldRect, "DoubleField", mDoubleValue);
                    
                    // 枚举多选
                    mEnumFlagsFieldValue = (EnumFlagsFieldValue)EditorGUI.EnumFlagsField(mEnumFlagsFieldRect, "EnumFlagsField", mEnumFlagsFieldValue);
                    
                    // 枚举单选
                    mEnumPopupValue = (EnumFlagsFieldValue)EditorGUI.EnumPopup(mEnumPopupRect,"EnumFlagsField", mEnumPopupValue);
                    
                    // 颜色渐变
                    mGradientFieldValue = EditorGUI.GradientField(mGradientFieldRect, "GradientField", mGradientFieldValue);
                }
                EditorGUI.EndDisabledGroup();
            }
        }
    }
}